Hyper Operators

Mr. Muskrat on 2005-04-15T20:30:10

I can't wait for the hyper operators to be implemented in pugs. Take the following example:

my $count;
my @apples = (32, 38, 37, 29, 41); # apples in each bushel
$count += $_ for @apples; # total number of apples
$count.say;
I'd like to do it like this (if it's valid to declare $count in this way):
my @apples = (32, 38, 37, 29, 41); # apples in each bushel
my $count +=<<@apples; # total number of apples
$count.say;


Another example where hyper operators would be nice:
my @credits = (5, 20, 125.50, 37.25);
my @debits = (3.66, 11.77, 23.99, 40.12, 9.95);
my @balances = @credits;
@balances[$_] -= @debits[$_] for (0 .. @debits.elems - 1);
my $total;
$total += $_ for @balances;
$total.say;
Could be written as:
my @credits = (5, 20, 125.50, 37.25);
my @debits = (3.66, 11.77, 23.99, 40.12, 9.95);
my @balances = @credits >>-<< @debits;
my $total +=<<@balances;
$total.say;


sum?

Juerd on 2005-04-15T22:42:51

my $count +=<<@apples; # total number of apples

That's not how you should use them, though, I think. With op= and then a list on the RHS, you're better off with good old for, or just sum:
my $count = sum @apples;
my $count = @apples.sum;

Re:sum?

Mr. Muskrat on 2005-04-16T00:38:40

Oooo! I didn't know about .sum! Thank you.